package com.weishe.loc;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class LocMapper extends Mapper<LongWritable, Text, Text, Loc> {

	private Text outputKey = new Text();
	private Loc loc = new Loc();

	public static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Loc>.Context context)
			throws IOException, InterruptedException {
		String str[] = value.toString().split("\t");

		loc.setLoc(str[3]);
		Date time;
		try {
			time = SDF.parse(str[4]);
			loc.setTime(time.getTime());
			outputKey.set(str[1] + "|" + loc.getHours());
			context.write(outputKey, loc);
		} catch (ParseException e) {
			e.printStackTrace();
		}

	}

}
